﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using Conexion;
using System.Threading;
using System.Net.Sockets;
using System.IO;

namespace Cliente
{
    public partial class ClientForm : Form
    {
        private BroadcastHandler broadcastService = null;
        private RequestManager requestService = null;
        private Config conf = null;

        private const string CMD_RAM = "01";
        private const string CMD_CPU = "02";
        private const string CMD_DISCO = "03";
        private const string CMD_SERV = "04";

        public ClientForm()
        {
            InitializeComponent();


            //  Carga la configuracion del XML del Cliente
            conf = new Config(""); //  

            // Inicio el servicio para enviar comandos a los servidiores
            requestService = new RequestManager(conf, this);

            // Inicia el servicio que monitorea el sistema y responde a las solicitudes del Manager
            broadcastService = new BroadcastHandler(conf, this);
            broadcastService.IniciarServicio();


        }
        
        private void btnCpu_Click(object sender, EventArgs e)
        {
            requestService.ConsultarManager(CMD_CPU);
        }

        private void btnDisco_Click(object sender, EventArgs e)
        {
            requestService.ConsultarManager(CMD_DISCO);
        }

        private void btnRam_Click(object sender, EventArgs e)
        {
            requestService.ConsultarManager(CMD_RAM);
        }

        private void btnActualizar_Click(object sender, EventArgs e)
        {
           int cant =  requestService.ConsultarManager(CMD_SERV);
           if (cant == 0)
           {
               btnCpu.Enabled = false;
               btnDisco.Enabled = false;
               btnRam.Enabled = false;
           }
           else
           {
               btnCpu.Enabled = true;
               btnDisco.Enabled = true;
               btnRam.Enabled = true;
           }

        }

        private void ClientForm_FormClosing(object sender, FormClosingEventArgs e)
        {          
            Application.Exit();
        }        
    }
}
